package com.feihao.zhou.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class Test {
    public static void main(String[] args) {
        Student student = new Student();

        student.eat("米饭");

        student.study();

        //动态代理增强study方法：
        StudentIntePro proxy = (StudentIntePro) Proxy.newProxyInstance(student.getClass().getClassLoader(), new Class[]{StudentIntePro.class}, new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                if (method.getName().equals("study")) {
                    System.out.println("去黑马培训学习");
                    return null;
                } else {
                    return method.invoke(student, args);
                }
            }
        });

        System.out.println("----------------代理对象执行------------------");
        proxy.study();
        proxy.eat("鸡腿");
    }
}
